package view.kasse;

import control.SalgsController;
import model.VareSalg;
import utility.PriceFormater;

/**
 *
 * @author Jeppe
 */
public class KasseVareListePanel extends javax.swing.JPanel {

    private final KassePanel kassePanel;
    private final VareSalg vareSalg;

    /**
     * Opretter nyt KasseVareListePanel
     *
     * @param kassePanel
     * @param vareSalg
     */
    public KasseVareListePanel(KassePanel kassePanel, VareSalg vareSalg) {
        initComponents();
        this.kassePanel = kassePanel;
        this.vareSalg = vareSalg;
        setSize(430, 42);
        setLabels();
    }

    /**
     * Sætter Labels i KasseVareListePanelet med VareSalgets data
     */
    public void setLabels() {
        vareNavnLabel.setText(vareSalg.getVare().getVarenavn());
        if (vareSalg.getValutaDKK()) {
            stykPrisLabel.setText(PriceFormater.formaterPrisTilString(vareSalg.getVare().getUdsalgsprisDKKMedRabat()));
        } else {
            stykPrisLabel.setText(PriceFormater.formaterPrisTilString(vareSalg.getVare().getUdsalgsprisEUROMedRabat()));
        }
        antalLabel.setText(vareSalg.getAntal() + "");
        salgsPrisLabel.setText(PriceFormater.formaterPrisTilString(vareSalg.getSalgsprisMedRabat()));
    }

    /**
     * Metoden sætter rabat på det pågældende VareSalg
     *
     * @param rabat int
     */
    public void setRabat(int rabat) {
        vareSalg.setRabat(rabat);
        kassePanel.opdaterKasseListeOgAktivtSalg();
        setLabels();
    }

    public VareSalg getVareSalg() {
        return vareSalg;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        Rabat = new javax.swing.JMenuItem();
        sletVareMenuItem = new javax.swing.JMenuItem();
        jPanel2 = new javax.swing.JPanel();
        panelKnap = new javax.swing.JButton();
        vareNavnTitelLabel = new javax.swing.JLabel();
        vareNavnLabel = new javax.swing.JLabel();
        stykPrisTitelLabel = new javax.swing.JLabel();
        stykPrisLabel = new javax.swing.JLabel();
        antalTitelLabel = new javax.swing.JLabel();
        antalLabel = new javax.swing.JLabel();
        prisTitelLabel = new javax.swing.JLabel();
        salgsPrisLabel = new javax.swing.JLabel();
        jSeparator7 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator6 = new javax.swing.JSeparator();

        Rabat.setText("Tilføj Rabat");
        Rabat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RabatActionPerformed(evt);
            }
        });
        jPopupMenu1.add(Rabat);

        sletVareMenuItem.setText("Fjern denne vare ▓");
        sletVareMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sletVareMenuItemActionPerformed(evt);
            }
        });
        jPopupMenu1.add(sletVareMenuItem);

        setOpaque(false);
        setPreferredSize(new java.awt.Dimension(430, 40));
        setRequestFocusEnabled(false);
        setLayout(null);

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setOpaque(false);
        jPanel2.setPreferredSize(new java.awt.Dimension(430, 40));
        jPanel2.setLayout(null);

        panelKnap.setContentAreaFilled(false);
        panelKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                panelKnapActionPerformed(evt);
            }
        });
        jPanel2.add(panelKnap);
        panelKnap.setBounds(1, 2, 430, 42);

        vareNavnTitelLabel.setText("Varenavn");
        jPanel2.add(vareNavnTitelLabel);
        vareNavnTitelLabel.setBounds(11, 3, 60, 14);

        vareNavnLabel.setText("Varenavn");
        jPanel2.add(vareNavnLabel);
        vareNavnLabel.setBounds(11, 20, 190, 17);

        stykPrisTitelLabel.setText("Pris/stk.");
        jPanel2.add(stykPrisTitelLabel);
        stykPrisTitelLabel.setBounds(216, 3, 50, 14);

        stykPrisLabel.setText("Stykpris");
        jPanel2.add(stykPrisLabel);
        stykPrisLabel.setBounds(216, 20, 70, 17);

        antalTitelLabel.setText("Antal");
        jPanel2.add(antalTitelLabel);
        antalTitelLabel.setBounds(299, 3, 40, 14);

        antalLabel.setText("Antal");
        jPanel2.add(antalLabel);
        antalLabel.setBounds(299, 20, 40, 17);

        prisTitelLabel.setText("Pris");
        jPanel2.add(prisTitelLabel);
        prisTitelLabel.setBounds(354, 3, 70, 14);

        salgsPrisLabel.setText("Pris");
        salgsPrisLabel.setVerifyInputWhenFocusTarget(false);
        jPanel2.add(salgsPrisLabel);
        salgsPrisLabel.setBounds(354, 20, 70, 17);

        jSeparator7.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator7);
        jSeparator7.setBounds(210, 2, 10, 42);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator3);
        jSeparator3.setBounds(292, 2, 10, 42);

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator6);
        jSeparator6.setBounds(348, 2, 2, 42);

        add(jPanel2);
        jPanel2.setBounds(0, 0, 430, 40);
    }// </editor-fold>//GEN-END:initComponents

    private void panelKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_panelKnapActionPerformed
        jPopupMenu1.show(this, getMousePosition().x, getMousePosition().y);
    }//GEN-LAST:event_panelKnapActionPerformed

    private void RabatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RabatActionPerformed
        kassePanel.visRabatPopUpPanel(vareSalg);
    }//GEN-LAST:event_RabatActionPerformed

    private void sletVareMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sletVareMenuItemActionPerformed
        SalgsController.getInstance().fjernVareFraSalg(vareSalg);
        kassePanel.opdaterKasseListeOgAktivtSalg();
    }//GEN-LAST:event_sletVareMenuItemActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem Rabat;
    private javax.swing.JLabel antalLabel;
    private javax.swing.JLabel antalTitelLabel;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JButton panelKnap;
    private javax.swing.JLabel prisTitelLabel;
    private javax.swing.JLabel salgsPrisLabel;
    private javax.swing.JMenuItem sletVareMenuItem;
    private javax.swing.JLabel stykPrisLabel;
    private javax.swing.JLabel stykPrisTitelLabel;
    private javax.swing.JLabel vareNavnLabel;
    private javax.swing.JLabel vareNavnTitelLabel;
    // End of variables declaration//GEN-END:variables
}
